package controller.sys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.JCXX.cl0001Service;
import Dao.JCXX.*;
import Model.JCXX.*;

/**
 * @author Administrator
 * 
 */
@Controller
public class TestController {
	@Autowired
	private Cl0001Mapper cl;
	@Autowired
	private cl0001Service cs;

	@RequestMapping("/sys/testeasyui")
	public Map<String, String> getMap() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping(value = "/getAll", produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getAddInfoAll(HttpServletRequest request) {
		try {
			List<Cl0001> list = cl.selectAll();
			JSONArray jsonarray = JSONArray.fromObject(list);
			String slist = jsonarray.toString();
			System.out.println(slist);
			request.setAttribute("addLists", list);
			return slist;
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("InfoMessage", "" + e.getMessage());
			return "test/test";
		}
	}

	@RequestMapping("/add")
	public String add(HttpServletRequest request) {
		try {
			// cs.add();
			cs.addT();
			return "sys/add";
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("InfoMessage", "" + e.getMessage());
			return "test/test";
		}
	}
}
